package com.gxar.uaa.server.base.controller;

import com.gxar.common.entity.Result;
import com.gxar.common.entity.login.LoginUserThread;
import com.gxar.common.entity.login.UserProfile;
import com.gxar.uaa.server.base.model.role.vo.response.RoleInfoResponse;
import com.gxar.uaa.server.db.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/3/15 13:42
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/admin/api/users")
@RequiredArgsConstructor
@Slf4j
public class UserController {

    private final RoleService roleService;

    @ApiOperation("用户角色列表")
    @GetMapping("/{userId}/roles")
    public Result<List<RoleInfoResponse>> userRoles(@PathVariable Long userId) {
        UserProfile userProfile = LoginUserThread.get();
        return Result.success(roleService.userRoles(userProfile.getApp(), userId));
    }
}
